package com.develop.data.buider;

import java.sql.SQLException;
import java.util.List;

import com.develop.data.base.Query;
import com.develop.data.base.mapping.DefaultMapping;
import com.develop.data.base.mapping.Mapping;
import com.develop.data.result.PageResult;

/**
 * 
 * @author starlee
 * 
 */
public class SQLTypeSelect extends AbstractSQLType
{

	@Override
	public Object doExecute(Query query)
	{
		try
		{
			Mapping mapping= new DefaultMapping(Class.forName(getReturnType()).newInstance());
			if (List.class.isAssignableFrom(getReturnTypeClass()))
			{
				return query.list(getSql(), mapping);

			} else if (PageResult.class.isAssignableFrom(getReturnTypeClass()))
			{
				return query.list(getSql(), mapping,getPageRow());
			} 
			else
			{
				return query.unique(getSql(), mapping);
			}
		} catch (InstantiationException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
